<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class opinion_model  extends MY_Model  {

    public $table = 'opinions';

	public function __construct() {
		$this->class_name = get_class ( $this );
		parent::__construct( $this->class_name, $this->table );
		parent::init( $this->class_name, $this->table );
	}
	
	public function getOpinion($filter = array()){
		$this->db->select($this->table . '.*,CONCAT_WS(" ",fe_users.last_name,fe_users.first_name ) as user_name,products.large_image, products.name , images1.url as img1 , images2.url as img2');
		
		$this->db->from($this->table);
		$this->db->join('fe_users','fe_users.id = ' . $this->table . '.user_id','LEFT');
		$this->db->join('products','products.id = ' . $this->table . '.product_id','LEFT');
		$this->db->join('images images1','products.id = images1.product_id','LEFT');
		$this->db->join('images images2','products.parent_id  = images2.product_id','LEFT');
		$this->db->where($this->table . '.published',1);
		
		if (isset($filter['language_id']) && strlen($filter['language_id'])){
			$this->db->where('products.language_id',$filter['language_id']);
		}
		if (isset($filter['limit']) && strlen($filter['limit'])){
			$this->db->limit($filter['limit']);
		}
		$this->db->group_by($this->table . '.id');
		$this->db->order_by($this->table . '.date','DESC');
		
		$query = $this->db->get();
		
		return $query;
	}
	
}